package com.xiaotou.struts.interceptor;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.xiaotou.db.pojo.WbUser;
import com.xiaotou.struts.action.LoginAction;
import com.xiaotou.utils.AuthUtils;

public class LoginInterceptor extends AbstractInterceptor {
    private static final long serialVersionUID = 1358600090729208361L;
    
    private static final String MAIN = "main";

    public String intercept(ActionInvocation invocation) throws Exception {
        final WbUser loginUser = AuthUtils.getLoginUser();
        final Object action = invocation.getAction();
        invocation.getProxy().getMethod();
        if (loginUser != null) {
            if (action instanceof LoginAction || action == null) {
                return MAIN;
            } else {
                return invocation.invoke();
            }
        } else if (action instanceof LoginAction) {
            return invocation.invoke();
        } else {
            return Action.LOGIN;
        }
    }
}